package com.hao.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;

import java.time.LocalDateTime;

/**
 * 传感器数据实体类
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@TableName("sensor_data")
public class SensorData {
    
    /**
     * 自增主键
     */
    @TableId(type = IdType.AUTO)
    private Long id;
    
    /**
     * 电压值(V)
     */
    private String voltage;
    
    /**
     * 电流值(A)
     */
    private String current;
    
    /**
     * 振动速度(mm/s)
     */
    private String vibrationSpeed;
    
    /**
     * 振动加速度(m/s²)
     */
    private String vibrationAcc;
    
    /**
     * 振动角速度(rad/s)
     */
    private String vibrationAngular;
    
    /**
     * 温度值(°C)
     */
    private String temperature;
    
    /**
     * 数据采集时间
     */
    private LocalDateTime collectTime;
    
    /**
     * 数据入库时间
     */
    private LocalDateTime createAt;
    
    /**
     * 从下划线分隔的字符串创建对象
     * @param dataString 数据字符串
     */
    public SensorData(String dataString) {
        String[] parts = dataString.split("_");
        if (parts.length == 7) {
            this.voltage = parts[0];
            this.current = parts[1];
            this.vibrationSpeed = parts[2];
            this.vibrationAcc = parts[3];
            this.vibrationAngular = parts[4];
            this.temperature = parts[5];
            this.collectTime = LocalDateTime.parse(parts[6], 
                java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
            this.createAt = LocalDateTime.now();
        }
    }
} 